const path = require('path');
const fs = require('fs');
module.exports = app => {
  const exports = {};

  exports.cluster = {
    listen: {
      port: 7001,
      hostname: '0.0.0.0',
    },
  };

  exports.multipart = {
    autoFields: false,
    defaultCharset: 'utf8',
    fieldNameSize: 100,
    fieldSize: '100kb',
    fields: 10,
    fileSize: '10mb',
    files: 10,
    fileExtensions: ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.txt'],
  };

  exports.siteFile = {
    '/favicon.ico': fs.readFileSync(
        path.join(app.baseDir, 'app/web/asset/images/favicon.ico')),
  };

  exports.view = {
    cache: false,
  };

  exports.vuessr = {
    renderOptions: {
      // 告诉 vue-server-renderer 去 app/view 查找异步 chunk 文件
      basedir: path.join(app.baseDir, 'app/view'),
    },
  };

  exports.logger = {
    consoleLevel: 'DEBUG',
    dir: path.join(app.baseDir, 'logs'),
  };

  exports.keys = '';

  exports.jwtKey = '';

  exports.middleware = [
    'access', 'cookieUser',
  ];

  exports.onerror = {
    html(err, ctx) {
      // console.error(err);
      // html hander
      ctx.body = `<h3>${err.message}</h3>`;
      ctx.status = 500;
    },
    json(err, ctx) {
      // console.error(err);
      // json hander
      ctx.body = err.message || '未知错误';
      ctx.status = 500;
    },
  };

  //nodemailer 设置
  exports.mail = {
    host: '',
    port: 465,
    secureConnection: true,
    auth: {
      user: '',
      pass: '',
    },
  };

  //存放截图路径
  exports.screenshot = {
    redisClientKey: 'screenshot_client:',
    parallel: 2,//允许同时打开网页标签进行截图的数量
    path: app.baseDir + '/screenshot',//保存截图的路径
    type: 'jpeg',//文件后缀格式
  };

  //Geetest配置
  exports.geetest = {
    geetest_id: '',
    geetest_key: '',
  };

  exports.redis = {
    client: {
      port: 63790,          // Redis port
      host: '127.0.0.1',   // Redis host
      password: '',
      db: 0,
    },
    agent: true,
  };

  //socket.io 配置
  exports.io = {
    namespace: {
      '/': {
        connectionMiddleware: ['auth'],
      },
    },
  };

  return exports;
};
